#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
struct ListNode
{
	int val;
	struct ListNode* next;
};
struct ListNode* CreateList(int* a, int n)
{
	struct  ListNode* phead = NULL, * ptail = NULL;
	int x = 0;
	for (int i = 0; i < n; ++i)
	{
		struct ListNode* newnode = (struct ListNode*)malloc(sizeof(struct ListNode));
		if (newnode == NULL)
		{
			perror("malloc fail");
			exit(-1);
		}
		else
		{
			newnode->val = a[i];
			newnode->next = NULL;
		}
		if (phead == NULL)
		{
			ptail = phead = newnode;
		}
		else
		{
			ptail->next = newnode;
			ptail = newnode;
		}
	}
	return phead;
}

struct ListNode* reverseList(struct ListNode* head)
{
	if (head == NULL)
		return NULL;
	struct ListNode* n1, * n2, * n3;
	n1 = head;
	n2 = NULL;
	n3 = n1->next;
	while (n1)
	{
		n1->next = n2;
		n2 = n1;
		n1 = n3;
		if (n3)
			n3 = n3->next;
	}
	return n2;
}

int main()
{
	int a[] = { 1,2,3,4,5,6 };
	struct ListNode* plist = CreateList(a, sizeof(a) / sizeof(int));
	reverseList(plist);
	return 0;
}